From d73898437f3de3f007f9e0c0a201920f3ba55a3a Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 16 Nov 2017 23:18:58 -0500 Subject: [PATCH] x11: Add gdk_x11_display_set_program_class The program class is a very X-specific concept. There should be x11-backend api to deal with it. --- docs/reference/gdk/gdk4-sections.txt | 1 + gdk/x11/gdkdisplay-x11.c | 33 +++++++++++++++++++++++++++- gdk/x11/gdkdisplay-x11.h | 1 + gdk/x11/gdkwindow-x11.c | 2 +- gdk/x11/gdkx11display.h | 3 +++ 5 files changed, 38 insertions(+), 2 deletions(-) diff --git a/docs/reference/gdk/gdk4-sections.txt b/docs/reference/gdk/gdk4-sections.txt index 97d1d25b75..ce11ad3c1b 100644 --- a/docs/reference/gdk/gdk4-sections.txt +++ b/docs/reference/gdk/gdk4-sections.txt @@ -902,6 +902,7 @@ gdk_x11_get_server_time gdk_x11_device_get_id gdk_x11_device_manager_lookup gdk_x11_display_open +gdk_x11_display_set_program_class gdk_x11_display_get_user_time gdk_x11_display_broadcast_startup_message gdk_x11_display_get_startup_notification_id diff --git a/gdk/x11/gdkdisplay-x11.c b/gdk/x11/gdkdisplay-x11.c index c89753a851..cdca966220 100644 --- a/gdk/x11/gdkdisplay-x11.c +++ b/gdk/x11/gdkdisplay-x11.c @@ -1663,7 +1663,7 @@ gdk_x11_display_open (const gchar *display_name) class_hint = XAllocClassHint(); class_hint->res_name = (char *) g_get_prgname (); - class_hint->res_class = (char *)gdk_get_program_class (); + class_hint->res_class = (char *) g_get_prgname (); /* XmbSetWMProperties sets the RESOURCE_NAME environment variable * from argv[0], so we just synthesize an argument array here. @@ -1760,6 +1760,35 @@ gdk_x11_display_open (const gchar *display_name) return display; } +/** + * gdk_x11_display_set_program_class: + * @display: a #GdkDisplay + * @program_class: a string + * + * Sets the program class. + * + * The X11 backend uses the program class to set the class name part + * of the `WM_CLASS` property on toplevel windows; see the ICCCM. + * + * Since: 3.94 + */ +void +gdk_x11_display_set_program_class (GdkDisplay *display, + const char *program_class) +{ + GdkX11Display *display_x11 = GDK_X11_DISPLAY (display); + XClassHint *class_hint; + + g_free (display_x11->program_class); + display_x11->program_class = g_strdup (program_class); + + class_hint = XAllocClassHint(); + class_hint->res_name = (char *) g_get_prgname (); + class_hint->res_class = (char *) program_class; + XSetClassHint (display_x11->xdisplay, display_x11->leader_window, class_hint); + XFree (class_hint); +} + /* * XLib internal connection handling */ @@ -2071,6 +2100,8 @@ gdk_x11_display_finalize (GObject *object) g_slice_free (GdkErrorTrap, trap); } + g_free (display_x11->program_class); + G_OBJECT_CLASS (gdk_x11_display_parent_class)->finalize (object); } diff --git a/gdk/x11/gdkdisplay-x11.h b/gdk/x11/gdkdisplay-x11.h index 60e6168b83..73189e2524 100644 --- a/gdk/x11/gdkdisplay-x11.h +++ b/gdk/x11/gdkdisplay-x11.h @@ -90,6 +90,7 @@ struct _GdkX11Display GHashTable *atom_to_virtual; /* Session Management leader window see ICCCM */ + char *program_class; Window leader_window; GdkWindow *leader_gdk_window; gboolean leader_window_title_set; diff --git a/gdk/x11/gdkwindow-x11.c b/gdk/x11/gdkwindow-x11.c index 84273f4019..ef99753cce 100644 --- a/gdk/x11/gdkwindow-x11.c +++ b/gdk/x11/gdkwindow-x11.c @@ -1000,7 +1000,7 @@ _gdk_x11_display_create_window_impl (GdkDisplay *display, class_hint = XAllocClassHint (); class_hint->res_name = (char *) g_get_prgname (); - class_hint->res_class = (char *) gdk_get_program_class (); + class_hint->res_class = (char *) display_x11->program_class; XSetClassHint (xdisplay, impl->xid, class_hint); XFree (class_hint); diff --git a/gdk/x11/gdkx11display.h b/gdk/x11/gdkx11display.h index 22035567a2..d43ebee747 100644 --- a/gdk/x11/gdkx11display.h +++ b/gdk/x11/gdkx11display.h @@ -76,6 +76,9 @@ const gchar * gdk_x11_display_get_startup_notification_id (GdkDisplay *d GDK_AVAILABLE_IN_ALL void gdk_x11_display_set_startup_notification_id (GdkDisplay *display, const gchar *startup_id); +GDK_AVAILABLE_IN_3_94 +void gdk_x11_display_set_program_class (GdkDisplay *display, + const char *program_class); GDK_AVAILABLE_IN_ALL void gdk_x11_display_set_cursor_theme (GdkDisplay *display, -- 2.30.2